<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
<h:outputStylesheet library="css" name="printing.css"></h:outputStylesheet>                 
                    <p:panel header="Search User Bills" >
                        
                        <h:panelGroup >
                            <h:panelGrid columns="2" style="min-width: 100%;">
                                <h:inputText autocomplete="off" id="txtSearch" value="#{billSearch.txtSearch}" >
                                    <f:ajax render="tblBills" execute="txtSearch" event="keyup" />
                                </h:inputText>
                                <p:commandButton  value="Export as Excel" ajax="false" styleClass="noPrintButton" style="float:right;">
                                    <pe:exporter type="xlsx" target="tblBills" fileName="Report by Referring Doctor"
                                                 facetBackground="#008000" facetFontSize="15" 
                                                 facetFontColor="#FFFFFF" facetFontStyle="BOLD" cellFontColor="#0000FF" cellFontSize="12"  cellFontStyle="NORMAL"  
                                                 fontName="Courier New"  />
                                </p:commandButton>
                            </h:panelGrid>
                            
                            <p:watermark value="Search by Bill Id (with or without letters), Patient Name or Phone Number" for="txtSearch" />

                            <h:panelGrid columns="5">

                                <h:panelGrid columns="2" >
                                    <h:outputLabel value="From Date"/>
                                    <p:calendar id="fromDate" value="#{billSearch.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >
                                        <f:ajax event="dateSelect" execute="tblBills  cmbUser"  render="tblBills toDate fromDate"/>
                                    </p:calendar>
                                </h:panelGrid>

                                <h:panelGrid columns="2" >
                                    <h:outputLabel value="To Date"/>                                
                                    <p:calendar id="toDate" value="#{billSearch.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >
                                        <f:ajax event="dateSelect" execute="tblBills cmbUser"  render="tblBills toDate fromDate"/>
                                    </p:calendar>
                                </h:panelGrid>


                                <h:panelGrid columns="2" >
                                    <h:outputLabel value="User Name"/>
                                    <p:autoComplete id="cmbUser" converter="webUs" 
                                                    forceSelection="true"
                                                    completeMethod="#{webUserController.completeUser}" styleClass="noPrintButton"
                                                    var="w" itemLabel="#{w.webUserPerson.name}" itemValue="#{w}"
                                                    value="#{billSearch.user}" >
                                        <f:ajax event="itemSelect" execute="@this"  render="tblBills toDate fromDate"/>
                                    </p:autoComplete>
                                </h:panelGrid>


                            </h:panelGrid>


                        </h:panelGroup>

                        <br/><br/>

                        <p:dataTable id="tblBills" value="#{billSearch.userBillsOwn}" var="bill"  >
                            <f:facet name="header">
                                <h:outputLabel value="Bills By Cashiers"/>
                            </f:facet>

                            <p:column headerText="Bill No" style="text-align: left;">
                                <f:facet name="header">
                                    <h:outputLabel value="Bill No"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" value="#{bill.insId}">
                                    <h:outputLabel  ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="To Department" >
                                <f:facet name="header">
                                    <h:outputLabel value="To Department"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" value="#{bill.toDepartment.name}">
                                    <h:outputLabel  ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Billing Centre" >
                                <f:facet name="header">
                                    <h:outputLabel value="Billing Centre"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" value="#{bill.institution.name}">
                                    <h:outputLabel  ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Bill Date" >
                                <f:facet name="header" >
                                    <h:outputLabel value="Bill Date"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint">
                                    <h:outputLabel value="#{bill.billDate}" >
                                        <f:convertDateTime pattern="dd MM yyyy"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Bill Time" >
                                <f:facet name="header">
                                    <h:outputLabel value="Bill Time"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.billTime}" >
                                        <f:convertDateTime pattern="hh:mm:ss a"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Client" >
                                <f:facet name="header">
                                    <h:outputLabel value="Client"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.patient.person.nameWithTitle}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Client Phone No" >
                                <f:facet name="header">
                                    <h:outputLabel value="Client Phone No"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.patient.person.phone}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Billed By" >
                                <f:facet name="header">
                                    <h:outputLabel value="Billed By"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.creater.webUserPerson.name}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Gross Value" style="text-align:right;">
                                <f:facet name="header">
                                    <h:outputLabel value="Gross Value"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.total}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Discount" style="text-align:right;">
                                <f:facet name="header">
                                    <h:outputLabel value="Discount"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.discount}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Net Value" style="text-align:right;">
                                <f:facet name="header">
                                    <h:outputLabel value="Net Value"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{bill.netTotal}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>


                            <p:column headerText="Cancelled User" >
                                <f:facet name="header">
                                    <h:outputLabel value="Cancelled User"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.cancelled}" value="#{bill.cancelledBill.creater.webUserPerson.name}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Cancelled Time" >
                                <f:facet name="header">
                                    <h:outputLabel value="Canceled Time"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.cancelled}" value="#{bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="hh:mm:ss a"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>


                            <p:column headerText="Cancelled Date" >
                                <f:facet name="header">
                                    <h:outputLabel value="Cancelled Date"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.cancelled}" value="#{bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd MM yyyy"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>


                            <p:column headerText="Refunded By" >
                                <f:facet name="header">
                                    <h:outputLabel value="Refunded By"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.refunded}" value="#{bill.refundedBill.creater.webUserPerson.name}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>


                            <p:column headerText="Refunded Time" >
                                <f:facet name="header">
                                    <h:outputLabel value="Refunded Time"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.refunded}" value="#{bill.refundedBill.createdAt}" >
                                        <f:convertDateTime pattern="hh:mm:ss a"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>


                            <p:column headerText="Refunded Date" >
                                <f:facet name="header">
                                    <h:outputLabel value="Refunded Date"/>
                                </f:facet>
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel rendered="#{bill.refunded}" value="#{bill.refundedBill.createdAt}" >
                                        <f:convertDateTime pattern="dd MM yyyy"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.bill}"/>
                                </h:commandLink>
                            </p:column>

                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
